/**
 * Author : jinhaibin
 * Date   : 2018/5/11
 * Time   : 上午10:55
 * desc   : 定制提示信息
 */

import {Message, Notification} from 'element-ui';

const MSG_TYPES = ['success', 'warning', 'error'];

/**
 * @param NoticeObj
 * @param preix 对外的方法前缀 例如传入的是 notice则 外部调用的方法就是 noticesuccess
 */
function getNotics(NoticeObj, preix) {
    let noticeFuns = {};
    for (let val of MSG_TYPES) {
        noticeFuns[preix + val] = function(msg) {
            let msgObj = {
                message: '',
                type: val
            };
            // 如果传入的是对象，就是对配置进行复写
            if (msg !== null && typeof msg === 'object') {
                msgObj = Object.assign(msgObj, msg);
            } else {
                msgObj.message = msg;
            }
            NoticeObj(msgObj);
        };
    }
    return noticeFuns;
}

export default {...getNotics(Message, ''), ...getNotics(Notification, 'notify')};
